﻿

using Grishko.DataTier;
using OutdoorLib.Context;
using OutdoorLib.BaseEntity;
using OutdoorLib.BaseEntity.Contract;
   
namespace OutdoorLib.BaseEntity.WS
{
    public class wsContract :EntitySingle 
    {


        public wsContract()
        {
            

            //Uncomment the following line if using designed components 
            //InitializeComponent(); 
        }
        
        public ContractList GetContractList(ContractList.sqlLoadStatment WhereStatment)
        {
            ContractList list = new ContractList { };
            //list.SqlStatment = WhereStatment;
            //list.Load();
            //foreach (ContractEntity item in list)
            //{
            //    if (null == item.Client) continue;
            //    item.Client.Load();
            //}
            return list;
        }
      
        public Contract.ContractEntity   GetContract(string ID)
        {
            return null;
        }

        public ContractEntity GetNewContract()
        {
            ContractEntity c = new ContractEntity();
            c.ID = c.ID + AgencyLib_GlobalConstants.qPrefNEW_RECORD;
            CacheTools.SetCacheObject(c.ID, c);
            return c;
        }

        /// <summary>
        /// Создать новый контракт
        /// </summary>
        /// <param name="SutrfaceItems"></param>
        /// <returns></returns>
        //[WebMethod(EnableSession = true)]
        //public Contract GetContract(ContractSidePeriodList SutrfaceItems)
        //{
        //    Contract c = new Contract();
        //    c.ContractSidePeriodList = SutrfaceItems;
        //    c.Save();        
        //    CacheTools.SetCacheObject(c.ID, c);
        //    return c;    

        //}


        public ContractEntity SaveContract(ContractEntity Contract)
        {
            if (Contract.ID.IndexOf(AgencyLib_GlobalConstants.qPrefNEW_RECORD) > -1)//режим вставки?
            {
                string s = Contract.ID;
                Contract.ID = Contract.ID.Replace(AgencyLib_GlobalConstants.qPrefNEW_RECORD, "");
                Contract.Save();
                CacheTools.ResetCache(s);
                return Contract;
            }
            Contract.Save();
            //Contract.Save(AppContext.GetSC().ConnectionString);
            //Contract.SetHash();
            return Contract;
        }




    }
}
